<template>
  <div class>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" width="900px" @close="close">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="排序" prop="sort" required>
          <el-input v-model.trim="form.sort" autocomplete="off" type="number" placeholder="请输入排序"></el-input>
        </el-form-item>
        <el-form-item label="分组名称" prop="name" required>
          <el-input v-model.trim="form.name" autocomplete="off" placeholder="请输入分组名称"></el-input>
        </el-form-item>
<!--        <el-form-item label="结算周期" prop="name">-->
<!--          <el-input v-model.trim="form.day" autocomplete="off" placeholder="请输入结算周期">-->
<!--            <template slot="append">天</template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="佣金比例" prop="type">
          <el-radio-group v-model="data.type">
            <el-radio label="1">按订单百分比抽成</el-radio>
            <el-radio label="2">按固定金额</el-radio>
          </el-radio-group>
        </el-form-item>
        <div v-if="data.type=='1'">
          <el-form-item label="商品抽佣比例">
            <el-input v-model="data.goodsPlatformProportion" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">%</template>
            </el-input>
            <el-input v-model="data.goodsStoreProportion" disabled style="width: 220px">
              <template slot="prepend">分店获得</template>
              <template slot="append">%</template>
            </el-input>/
            <el-input v-model="data.goodsDownMoney" style="width: 220px">
              <template slot="prepend">最低抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="配送费抽佣比例">
            <el-input v-model="data.deliverPlatformProportion" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">%</template>
            </el-input>
            <el-input v-model="data.deliverStoreProportion" disabled style="width: 220px">
              <template slot="prepend">分店获得</template>
              <template slot="append">%</template>
            </el-input>/
            <el-input v-model="data.deliverDownMoney" style="width: 220px">
              <template slot="prepend">最低抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="包装费抽佣比例">
            <el-input v-model="data.boxPlatformProportion" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">%</template>
            </el-input>
            <el-input v-model="data.boxStoreProportion" disabled style="width: 220px">
              <template slot="prepend">分店获得</template>
              <template slot="append">%</template>
            </el-input>/
            <el-input v-model="data.boxDownMoney" style="width: 220px">
              <template slot="prepend">最低抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="当面付抽佣比例">
            <el-input v-model="data.cashierPlatformProportion" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">%</template>
            </el-input>
            <el-input v-model="data.cashierStoreProportion" disabled style="width: 220px">
              <template slot="prepend">分店获得</template>
              <template slot="append">%</template>
            </el-input>/
            <el-input v-model="data.cashierDownMoney" style="width: 220px">
              <template slot="prepend">最低抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="快餐抽佣比例">
            <el-input v-model="data.fastPlatformProportion" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">%</template>
            </el-input>
            <el-input v-model="data.fastStoreProportion" disabled style="width: 220px">
              <template slot="prepend">分店获得</template>
              <template slot="append">%</template>
            </el-input>/
            <el-input v-model="data.fastDownMoney" style="width: 220px">
              <template slot="prepend">最低抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="店内抽佣比例">
            <el-input v-model="data.inStorePlatformProportion" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">%</template>
            </el-input>
            <el-input v-model="data.inStoreStoreProportion" disabled style="width: 220px">
              <template slot="prepend">分店获得</template>
              <template slot="append">%</template>
            </el-input>/
            <el-input v-model="data.inStoreDownMoney" style="width: 220px">
              <template slot="prepend">最低抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </div>
        <div v-if="data.type=='2'">
          <el-form-item label="商品抽成金额">
            <el-input v-model="data.goodsFixedMoney" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="配送费抽成金额">
            <el-input v-model="data.deliverFixedMoney" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="包装费抽成金额">
            <el-input v-model="data.boxFixedMoney" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="当面付抽成金额">
            <el-input v-model="data.cashierFixedMoney" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="快餐抽成金额">
            <el-input v-model="data.fastFixedMoney" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="店内抽成金额">
            <el-input v-model="data.inStoreFixedMoney" style="width: 220px">
              <template slot="prepend">总店抽佣</template>
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="close">取 消</el-button>
        <el-button size="medium" type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { storeCategory } from '@/api/shop';

export default {
  name: 'goodlistedit',
  created() {},
  data() {
    return {
      form: {
        id: '',
        item: '1',
        sort: '',
        name: ''
      },
      data: {
        type: '1',
        goodsPlatformProportion: 0,
        goodsStoreProportion: 100,
        goodsDownMoney: 0,
        deliverPlatformProportion: 0,
        deliverStoreProportion: 100,
        deliverDownMoney: 0,
        boxPlatformProportion: 0,
        boxStoreProportion: 100,
        boxDownMoney: 0,
        goodsFixedMoney: 0,
        deliverFixedMoney: 0,
        boxFixedMoney: 0,
        cashierPlatformProportion: 0,
        cashierStoreProportion: 100,
        cashierDownMoney: 0,
        cashierFixedMoney: 0,
        fastPlatformProportion: 0,
        fastStoreProportion: 100,
        fastDownMoney: 0,
        fastFixedMoney: 0,
        inStorePlatformProportion: 0,
        inStoreStoreProportion: 100,
        inStoreDownMoney: 0,
        inStoreFixedMoney: 0
      },
      title: '',
      dialogFormVisible: false
    };
  },
  components: {},
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '添加';
      } else {
        this.title = '编辑';
        this.form = Object.assign({}, row);
        this.data = Object.assign({}, row.data);
        this.data.goodsStoreProportion = 100 - this.data.goodsPlatformProportion;
        this.data.deliverStoreProportion = 100 - this.data.deliverPlatformProportion;
        this.data.boxStoreProportion = 100 - this.data.boxPlatformProportion;
        this.data.cashierStoreProportion = 100 - this.data.cashierPlatformProportion;
        this.data.fastStoreProportion = 100 - this.data.fastPlatformProportion;
        this.data.inStoreStoreProportion = 100 - this.data.inStorePlatformProportion;
      }
      this.dialogFormVisible = true;
    },
    close() {
      this.$refs['form'].resetFields();
      this.form = this.$options.data().form;
      this.dialogFormVisible = false;
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form2 = Object.assign({}, this.data);
          this.form2.id = this.form.id;
          this.form2.item = this.form.item;
          this.form2.sort = this.form.sort;
          this.form2.name = this.form.name;
          console.log(this.form2, this.data);
          const { msg } = await storeCategory(this.form2);
          this.$baseMessage(msg, 'success');
          this.$emit('fetchData');
          this.close();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
